﻿using System.Collections;
using System.Linq;
using Gp.Scripts.Data.Skills;
using Gp.Scripts.Core;

namespace Gp.AI {
    [CreateNodeMenu("使用技能/武器技能")]
    public class UseWeaponAbilityAINode : NormalAINode {
        public WeaponAbilityEntityConfig AbilityEntity;

        public override AINodeEntry NodeEntry() {
            return new UseWeaponAbilityAINodeEntry(this);
        }
    }


    public class UseWeaponAbilityAINodeEntry : NormalAINodeEntry<UseWeaponAbilityAINode> {
        public UseWeaponAbilityAINodeEntry(UseWeaponAbilityAINode data) : base(data) { }
        private WeaponAbilityEntity _ability;
        private SkillContext _context;
        
        
        protected override void OnInit() {
            // _ability = Unit.ComSkill.WeaponAbilities.FirstOrDefault(x =>
            //     x.Weapon == Unit.ComEquip.CurWeapon && x.EntityConfig == Data.AbilityEntity
            // );
        }

        protected override void PreCalculate() {
            _context = _ability.GetAIContext();
        }

        public override bool ShouldPerform() {
            return _ability != null && _ability.CanSelect().Result() && _context != null;
        }


        protected override AIActionArgs GetActionInfo() {
            return AIActionArgs.Build(_ability);
        }


        public override IEnumerator OnExecute() {
            yield return _ability.AIExecute(_context);
        }
    }
}